import React from 'react';
import {connect} from 'react-redux'
import Counter from '../components/Counter'

import {increment, decrement, reset} from "../actions/counter";

// Map Redux State to component props
function mapStateToProps(state, ownProps) {
    // console.log('call mapStateToProps. state:'+JSON.stringify(state));
    return {
        count: state.reducer_counter.count,
        hello: state.reducer_counter.hello,
    }
}
// Map Redux actions to component props
const mapDispatchToProps = dispatch => {
    // console.log('call mapDispatchToProps. dispatch:'+dispatch);
    return {
        onIncrease: () => {
            dispatch(increment())
        },
        onDecrement: () => {
            dispatch(decrement())
        },
        onReset: () => {
            dispatch(reset())
        },
    }
};
// Connect component
// connect方法关联展示型组件
const ConnectCounter= connect(
    mapStateToProps,
    mapDispatchToProps
)(Counter);

export default ConnectCounter;
